//
//  QuickLookExampleViewController.m
//  QuickLookExample
//

#import "QuickLookExampleViewController.h"

@implementation QuickLookExampleViewController

- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
	return 1;
}

- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller
					 previewItemAtIndex:(NSInteger)index {
	NSString *documentLocation = [[NSBundle mainBundle]
								  pathForResource:@"iphone_user_guide"
								  ofType:@"pdf"];
	NSURL *myQLDocument = [NSURL fileURLWithPath:documentLocation];
	return myQLDocument;
}

- (void)showPreview:(id)sender {
	[self presentModalViewController:qlViewController animated:YES];
}

- (void)createUI {
	UIButton *btnShowQuickLook = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	btnShowQuickLook.frame = CGRectMake(60, 400, 200, 34);
	[btnShowQuickLook setTitle:@"Show Preview" forState:UIControlStateNormal];
	[btnShowQuickLook addTarget:self
						 action:@selector(showPreview:)
			   forControlEvents:UIControlEventTouchUpInside];
	[self.view addSubview:btnShowQuickLook];
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	qlViewController = [[QLPreviewController alloc] init];
	qlViewController.dataSource = self;
	[self createUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
    [super dealloc];
}

@end
